#pragma once
#include "RBTree.hpp"

template<class K,class V>
class Map
{
public:
	class KeyofT
	{
	public:
		const K& operator()(const pair<K,V>& x)
		{
			return x.first;
		}
	};
	using iterator = typename RBTree<K, pair<const K,V>, KeyofT>::iterator;
	using const_iterator = typename RBTree<K, pair<const K, V>, KeyofT>::const_iterator;
	iterator begin()
	{
		return _t.begin();
	}
	iterator end()
	{
		return _t.end();
	}
	const_iterator begin()const
	{
		return _t.begin();
	}
	const_iterator end()const
	{
		return _t.end();
	}
	iterator find(const K& x)
	{
		return _t.find(x);
	}
	pair<iterator, bool> insert(  pair<const K, V> x)
	{
		return _t.insert(x);
	}
	V& operator[](const K& key)
	{
		pair<iterator, bool> ret = insert({ key,K() });
		auto it = ret.first;
		return it->second;
	}
private:
	RBTree<K, pair<const K, V>, KeyofT> _t;
};